 <template lang="html">
  <div class="global">
    <div class="g-content">
      <div class="content">
        <div class="section">
          <span class="left">订单号</span>
          <span class="right">{{orderData.oid}}</span>
        </div>
        <div class="section">
          <span class="left">租用时间</span>
          <span class="right">{{orderData.start_time}}~{{orderData.end_time}}</span>
        </div>
        <div class="section">
          <span class="left">下单时间</span>
          <span class="right">{{orderData.create_time}}</span>
        </div>
      </div>
      <div class="content">
        <div class="section">
          <span class="left">姓名</span>
          <span class="right">{{orderData.rent_name}}</span>
        </div>
        <div class="section">
          <span class="left">手机号码</span>
          <span class="right">{{orderData.rent_cellphone}}</span>
        </div>
        <div class="section">
          <span class="left">公司名称</span>
          <span class="right">{{orderData.rent_company}}</span>
        </div>
        <div class="use">
          <p class="title">用途</p>
          <div class="text">{{orderData.rent_use}}</div>
        </div>
      </div>
      <div class="content">
        <div class="section">
          <span class="left">订单总额</span>
          <span class="right">{{orderData.amount}}</span>
        </div>
      </div>
      <div class="footer">
        <div class="btn" v-if="orderData.ostatus == 2 || orderData.ostatus == 3" @click="toDelete">删除</div>
        <div class="btn" v-else @click="toCancel">取消订单</div>
      </div>
    </div>
  </div>
</template>

<script>
import api from '@/utils/api'
export default {
  data () {
    return {
      orderData: {},
      rentTime: '',
      oid: ''
    }
  },
  onShow () {
    this.oid = this.$root.$mp.query.oid
    this.opmeetingordersdetail()
  },
  methods: {
    opmeetingordersdetail () {
      var param = {}
      param['oid'] = this.oid
      const opmeetingordersdetail = api.opmeetingordersdetail(param)
      opmeetingordersdetail.then(d => {
        if (d.code === 200) {
          this.orderData = d.data
          this.orderData.start_time = this.orderData.start_time.slice(0, 16)
          this.orderData.end_time = this.orderData.end_time.slice(11, 16)
          var date = new Date(parseInt(this.orderData.create_time) * 1000)
          this.orderData.create_time = date.toLocaleDateString() + ' ' + (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':' + (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes())
        }
      })
      .catch((e) => {
        console.log(e)
      })
    },
    opmeetingorderssave (ostatus) {
      var param = {}
      param['oid'] = this.oid
      param['ostatus'] = ostatus
      const opmeetingorderssave = api.opmeetingorderssave(param)
      opmeetingorderssave.then(d => {
        if (d.code === 200) {
          if (ostatus === 2) {
            wx.showToast({
              title: '取消成功',
              icon: 'success'
            })
          } else {
            wx.showToast({
              title: '删除成功',
              icon: 'success'
            })
          }
          wx.navigateBack()
        }
      })
      .catch((e) => {
        console.log(e)
      })
    },
    toCancel () {
      this.opmeetingorderssave(2)
    },
    toDelete () {
      this.opmeetingorderssave(4)
    }
  }
}
</script>

<style lang="css">
  @import "./order_detail.css";
</style>
